﻿using PLCTest.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PLCTest.BO
{
    public class ZJNDoubleScMessageWriteWcsActionBO
    {
        /// <summary>
        /// 启动命令
        /// </summary>
        public bool Startcommand { get; set; }
        /// <summary>
        /// 报警复位
        /// </summary>
        public bool Alarmreset { get; set; }
        /// <summary>
        /// 自动任务复位
        /// </summary>
        public bool Taskreset { get; set; }
        /// <summary>
        /// WCS消防命令
        /// </summary>
        public bool WCSfirecommand { get; set; }

        /// <summary>
        /// WCS拍照温度无异常
        /// </summary>
        public bool WCSfireOK { get; set; }
        /// <summary>
        /// WCS拍照温度异常
        /// </summary>
        public bool WCSfireNG { get; set; }
        /// <summary>
        /// WCS拍照人工确认
        /// </summary>
        public bool WCSfireAffirm { get; set; }

        /// <summary>
        /// 手动任务复位
        /// </summary>
        public bool ManualTaskreset { get; set; }

        /// <summary>
        /// 1号叉工作序号
        /// </summary>
        public int JobOnenumber { get; set; }
        /// <summary>
        /// 工作命令代码
        /// </summary>
        public short Jobordercode { get; set; }
        /// <summary>
        /// 1号叉启始行fromPC
        /// </summary>
        public short StartOnelinefromPC { get; set; }
        /// <summary>
        /// 1号叉启始列fromPC
        /// </summary>
        public short StartOnecolumnfromPC { get; set; }
        /// <summary>
        /// 1号叉启始层fromPC
        /// </summary>
        public short StartOnelayerfromPC { get; set; }
        /// <summary>
        /// 1号叉目标行fromPC
        /// </summary>
        public short TargetOnelinefromPC { get; set; }
        /// <summary>
        /// 1号叉目标列fromPC
        /// </summary>
        public short TargetOnecolumnfromPC { get; set; }
        /// <summary>
        /// 1号叉目标层fromPC
        /// </summary>
        public short TargetOnelayerfromPC { get; set; }
        /// <summary>
        /// WCS过账完成
        /// </summary>
        public short WCSpostingcompleted { get; set; }

        public short yuliu8 { get; set; }
        /// <summary>
        /// 心跳信号
        /// </summary>
        public short HeartBeat { get; set; }
        public short yuliu10 { get; set; }
        public short yuliu11 { get; set; }
        public short yuliu12 { get; set; }

        public bool beiyong1 { get; set; }

        public bool beiyong2 { get; set; }

        public bool beiyong3 { get; set; }

        public int beiyong4 { get; set; }

        public int beiyong5 { get; set; }

        public int beiyong6 { get; set; }

        public int beiyong7 { get; set; }

        public int beiyong8 { get; set; }

        public int beiyong9 { get; set; }

        public int beiyong10 { get; set; }


        /// <summary>
        /// 2号叉工作序号
        /// </summary>
        public int JobTwonumber { get; set; }

        /// <summary>
        /// 2号叉启始行fromPC
        /// </summary>
        public short StartTwolinefromPC { get; set; }
        /// <summary>
        /// 2号叉启始列fromPC
        /// </summary>
        public short StartTwocolumnfromPC { get; set; }
        /// <summary>
        /// 2号叉启始层fromPC
        /// </summary>
        public short StartTwolayerfromPC { get; set; }
        /// <summary>
        /// 2号叉目标行fromPC
        /// </summary>
        public short TargetTwolinefromPC { get; set; }
        /// <summary>
        /// 2号叉目标列fromPC
        /// </summary>
        public short TargetTwocolumnfromPC { get; set; }
        /// <summary>
        /// 2号叉目标层fromPC
        /// </summary>
        public short TargetTwolayerfromPC { get; set; }

        /// <summary>
        /// 取1货叉选择 0复位  1 1号货叉 2 2号货叉  3  双货叉
        /// </summary>
        public short StartOnePalletForkChoice { get; set; }

        /// <summary>
        /// 取2货叉选择 0复位  1 1号货叉 2 2号货叉  3  双货叉
        /// </summary>
        public short StartTwoPalletForkChoice { get; set; }

        /// <summary>
        /// 放1货叉选择 0复位  1 1号货叉 2 2号货叉  3  双货叉
        /// </summary>
        public short TargetOnePalletForkChoice { get; set; }

        /// <summary>
        /// 放2货叉选择 0复位  1 1号货叉 2 2号货叉  3  双货叉
        /// </summary>
        public short TargetTwoPalletForkChoice { get; set; }

        //public short beiyong11 { get; set; }

        ///// <summary>
        ///// 1号货叉托盘条码
        ///// </summary>
        //public string PalletBarcode1 { get; set; }

        ///// <summary>
        ///// 2号货叉托盘条码
        ///// </summary>
        //public string PalletBarcode2 { get; set; }



        public byte[] Deserialize()
        {
            //对象序列化为数组
            byte[] bytes = new byte[86];
            HelperByte.SetBitAt(ref bytes, 0, 0, Startcommand);
            HelperByte.SetBitAt(ref bytes, 0, 1, Alarmreset);
            HelperByte.SetBitAt(ref bytes, 0, 2, Taskreset);
            HelperByte.SetBitAt(ref bytes, 0, 3, WCSfirecommand);
            HelperByte.SetBitAt(ref bytes, 0, 4, WCSfireOK);
            HelperByte.SetBitAt(ref bytes, 0, 5, WCSfireNG);
            HelperByte.SetBitAt(ref bytes, 0, 6, WCSfireAffirm);
            HelperByte.SetBitAt(ref bytes, 0, 7, ManualTaskreset);

            HelperByte.SetDIntAt(bytes, 2, JobOnenumber);
            HelperByte.SetIntAt(bytes, 6, Jobordercode);
            HelperByte.SetIntAt(bytes, 8, StartOnelinefromPC);
            HelperByte.SetIntAt(bytes, 10, StartOnecolumnfromPC);
            HelperByte.SetIntAt(bytes, 12, StartOnelayerfromPC);
            HelperByte.SetIntAt(bytes, 14, TargetOnelinefromPC);
            HelperByte.SetIntAt(bytes, 16, TargetOnecolumnfromPC);
            HelperByte.SetIntAt(bytes, 18, TargetOnelayerfromPC);
            HelperByte.SetIntAt(bytes, 20, WCSpostingcompleted);
            HelperByte.SetIntAt(bytes, 22, yuliu8);
            HelperByte.SetIntAt(bytes, 24, HeartBeat);

            HelperByte.SetIntAt(bytes, 26, yuliu10);
            HelperByte.SetIntAt(bytes, 28, yuliu11);
            HelperByte.SetIntAt(bytes, 30, yuliu12);

            HelperByte.SetBitAt(ref bytes, 32, 0, beiyong1);
            HelperByte.SetBitAt(ref bytes, 32, 1, beiyong2);
            HelperByte.SetBitAt(ref bytes, 32, 2, beiyong3);
            HelperByte.SetDIntAt(bytes, 34, beiyong4);
            HelperByte.SetDIntAt(bytes, 38, beiyong5);
            HelperByte.SetDIntAt(bytes, 42, beiyong6);
            HelperByte.SetDIntAt(bytes, 46, beiyong7);
            HelperByte.SetDIntAt(bytes, 50, beiyong8);
            HelperByte.SetDIntAt(bytes, 54, beiyong9);
            HelperByte.SetDIntAt(bytes, 58, beiyong10);

            HelperByte.SetDIntAt(bytes, 62, JobTwonumber);
            HelperByte.SetIntAt(bytes, 66, StartTwolinefromPC);
            HelperByte.SetIntAt(bytes, 68, StartTwocolumnfromPC);
            HelperByte.SetIntAt(bytes, 70, StartTwolayerfromPC);
            HelperByte.SetIntAt(bytes, 72, TargetTwolinefromPC);
            HelperByte.SetIntAt(bytes, 74, TargetTwocolumnfromPC);
            HelperByte.SetIntAt(bytes, 76, TargetTwolayerfromPC);

            HelperByte.SetIntAt(bytes, 78, StartOnePalletForkChoice);
            HelperByte.SetIntAt(bytes, 80, StartTwoPalletForkChoice);
            HelperByte.SetIntAt(bytes, 82, TargetOnePalletForkChoice);
            HelperByte.SetIntAt(bytes, 84, TargetTwoPalletForkChoice);

            //HelperByte.SetIntAt(bytes, 86, beiyong11);

            ////写入长度
            ////预留长度
            //HelperByte.SetByteAt(bytes, 88, 30);
            ////实际长度
            //byte length1 = Convert.ToByte(PalletBarcode1.Length);
            //HelperByte.SetByteAt(bytes, 89, length1);
            ////实际内容
            //HelperByte.SetCharsAt(bytes, 90, PalletBarcode1);
            ////预留长度
            //HelperByte.SetByteAt(bytes, 120, 30);
            ////实际长度
            //byte length2 = Convert.ToByte(PalletBarcode2.Length);
            //HelperByte.SetByteAt(bytes, 121, length2);
            ////实际内容
            //HelperByte.SetCharsAt(bytes,122,PalletBarcode2);
            return bytes;
        }
    }
}
